﻿@{
    ViewBag.Title = "OptionProduct";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script>
    $(function () {
        InitialPage();
        GetGrid();
    });
    //初始化页面
    function InitialPage() {
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 108.5);
            }, 200);
            e.stopPropagation();
        });
    }
    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            url: "../../SystemManage/DataItemList/GetListJson?encode=Client_ProductInfo",
            datatype: "json",
            height: $(window).height() - 108.5,
            autowidth: true,
            colModel: [
                { label: '主键', name: 'F_ItemDetailId', hidden: true },
                { label: "商品编号", name: "F_ItemValue", width: 100, align: "left", sortable: false },
                { label: "商品名称", name: "F_ItemName", width: 300, align: "left", sortable: false }
            ],
            pager: false,
            rowNum: "1000",
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            ondblClickRow: function () {
                //alert(1)
            }
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            $gridTable.jqGrid('setGridParam', {
                postData: {
                    condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
                    keyword: $("#txt_Keyword").val()
                }
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }
    //保存表单
    function AcceptClick(callback) {
        var row = $("#gridTable").jqGridRow()[0];
        if (row.F_ItemDetailId) {
            var datajson = {
                F_ProductId: row.F_ItemDetailId,
                F_ProductCode: row.F_ItemValue,
                F_ProductName: row.F_ItemName,
            }
            callback(datajson);
            dialogClose();
        } else {
            dialogMsg('请选择需要选择的商品信息！', 0);
        }
    }
</script>
<div class="titlePanel">
    <div class="title-search">
        <table>
            <tr>
                <td>
                    <div id="queryCondition" class="btn-group">
                        <a class="btn btn-default dropdown-text" data-toggle="dropdown">选择条件</a>
                        <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            <li><a data-value="ItemValue">商品编号</a></li>
                            <li><a data-value="ItemName">商品名称</a></li>
                        </ul>
                    </div>
                </td>
                <td style="padding-left: 2px;">
                    <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                </td>
                <td style="padding-left: 5px;">
                    <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="gridPanel">
    <table id="gridTable"></table>
</div>
